package com.edgclub.edg.uc;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.edgclub.edg.R;
import com.edgclub.edg.model.Reply;

/**
 * 确定取消的对话框
 * 
 * @author 陈坤彬
 *
 */
public class TopicDetailDialog extends Dialog {

	private TextView tv1,tv2,tv3,tv_line2 , tv_line3;
	private Context context;

	private Dialog dialog;

	private TopicDetailDialog instance;

	public static TopicDetailDialog create(Context context, boolean isMe , boolean isDeleteReply) {
		TopicDetailDialog instance = new TopicDetailDialog(context,isMe , isDeleteReply);
		return instance;

	}

	private TopicDetailDialog(Context context, boolean isMe , boolean isDeleteReply) {
		super(context, R.style.MyAlertDialog);
		init(context,isMe , isDeleteReply);
	}

	private void init(Context context, boolean isMe , boolean isDeleteReply) {
		this.context = context;
		WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
		lp.width = context.getResources().getDisplayMetrics().widthPixels;

		View contentView = LayoutInflater.from(context).inflate(
				R.layout.layout_topic_detail_dialog, null);

		setContentView(contentView, lp);
		tv1 = (TextView) contentView.findViewById(R.id.tv1);
		tv_line2 = (TextView) contentView.findViewById(R.id.tv_line2);
		tv_line3 = (TextView) contentView.findViewById(R.id.tv_line3);
		tv2 = (TextView) contentView.findViewById(R.id.tv2);
		tv3 = (TextView) contentView.findViewById(R.id.tv3);
		tv1.setVisibility(View.VISIBLE);
		tv2.setVisibility(View.VISIBLE);
		if (isMe){
			tv3.setVisibility(View.VISIBLE);
			tv_line3.setVisibility(View.VISIBLE);
			tv2.setVisibility(View.GONE);
			tv_line2.setVisibility(View.GONE);
		} else {
			tv3.setVisibility(View.GONE);
			tv_line3.setVisibility(View.GONE);
			tv2.setVisibility(View.VISIBLE);
			tv_line2.setVisibility(View.VISIBLE);
		}
		if (isDeleteReply){
			tv3.setVisibility(View.VISIBLE);
			tv_line3.setVisibility(View.VISIBLE);
		}
	}

	/**
	 * 设置回复的监听
	 */
	public void setReplyListener(
			final ReplyClickListener replyClickListener) {
		tv1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				replyClickListener.replyClick();
			}
		});
	}

	/**
	 * 设置回复的监听
	 */
	public void setReportListener(
			final ReportClickListener reportClickListener) {
		tv2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				reportClickListener.reportClick();
			}
		});
	}

	/**
	 * 设置取消的监听
	 */
	public void setDeletelListener(
			final DeleteClickListener deleteClickListener) {
		tv3.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				deleteClickListener.deleteClick();
			}
		});
	}

	public void setTitle(int res) {
		setTitle(context.getResources().getString(res));
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		dismiss();
		return false;
	}


	public interface ReplyClickListener {
		public void replyClick();

	}
	public interface ReportClickListener {
		public void reportClick();

	}

	public interface DeleteClickListener {
		public void deleteClick();
	}

	public void setTv1(Reply reply){
		tv1.setText("回复@" + reply.getUser().getNick());
	}
	

}
